package com.example.fw;

import java.io.IOException;
import java.util.Properties;

public class ApplicationManager {


	private static ApplicationManager singleton;
	private Properties props;
	private WebDriverHelper webDriverHelper;
	private HibernateHelper hibernateHelper;
	private AccountHelper accountHelper;
	private MailHelper mailHelper;
	private JamesHelper jamesHelper;
	private FtpHelper ftpHelper;
	

	
	public static ApplicationManager getInstance() throws IOException {
		if(singleton== null){
			singleton = new ApplicationManager();
		}
		return singleton;
	}
		
	public void stop() {
		if (webDriverHelper != null) {
			webDriverHelper.stop();
			ftpHelper.restoreConfig();
			}
	}
	
	public void setProperties(Properties props){
		this.props = props;
	}	

	public String getProperty(String key, String defaultValue){
	return props.getProperty(key, defaultValue);	
	}
	
	public String getProperty(String key){
		return props.getProperty(key);	
		}
	
	public HibernateHelper getHibernateHelper() {
		if (hibernateHelper == null) {
			hibernateHelper = new HibernateHelper(this);
		}
		return hibernateHelper;
	}

	public WebDriverHelper getWebDriverHelper() {
		if (webDriverHelper == null) {
			webDriverHelper = new WebDriverHelper(this);
		}
		return webDriverHelper;
	}

	public AccountHelper getAccountHelper() {
		if (accountHelper == null) {
			accountHelper = new AccountHelper(this);
		}
		return accountHelper;
	}

	public MailHelper getMailHelper() {
		if (mailHelper == null) {
			mailHelper = new MailHelper(this);
		}
		return mailHelper;
	}

	public JamesHelper getJamesHelper() {
		if (jamesHelper == null) {
			jamesHelper = new JamesHelper(this);
		}
		return jamesHelper;
	}

	public FtpHelper getFtpHelper() {
		if (ftpHelper == null) {
			ftpHelper = new FtpHelper(this);
		}
		return ftpHelper;
	}
	
}